//
//  KeepTimeView.m
//  WWXELuShang
//
//  Created by lanou on 15/12/23.
//  Copyright © 2015年 lanou. All rights reserved.
//

#import "KeepTimeView.h"

@implementation KeepTimeView

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = kBackGroundColor;
        [self addSubview:self.backgroundView];
        [self addSubview:self.stopButton];
        [self.backgroundView addSubview:self.timeLabel];
        [self.backgroundView addSubview:self.alertTimeLabel];
        [self addSubview:self.showView];
        [self.showView addSubview:self.showMapButton];
        
    }
    return self;
}

- (UIView *)backgroundView {
    if (!_backgroundView) {
        _backgroundView = [[UIView alloc] initWithFrame:CGRectMake(0, kWidth / 10, kWidth, kHeight / 2)];
        _backgroundView.backgroundColor = [UIColor whiteColor];
    }
    return _backgroundView;
}


- (UILabel *)timeLabel {
    if (!_timeLabel) {
        _timeLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, kWidth, self.backgroundView.frame.size.height / 3)];
        _timeLabel.textAlignment = NSTextAlignmentCenter;
        _timeLabel.font = [UIFont boldSystemFontOfSize:self.backgroundView.frame.size.height / 5];
        _timeLabel.text = @"00:00:00";
        _timeLabel.textColor = [UIColor grayColor];
        _timeLabel.center = self.backgroundView.center;
    }
    return _timeLabel;
}


//距离提醒时间
- (UILabel *)alertTimeLabel {
    
    if (!_alertTimeLabel) {
        _alertTimeLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, kWidth, kWidth / 10)];
        _alertTimeLabel.center = CGPointMake(kWidth /2 , self.timeLabel.frame.origin.y - kWidth / 5 );
        _alertTimeLabel.font = [UIFont boldSystemFontOfSize:20];
//        _alertTimeLabel.text = @"停车时间";
        _alertTimeLabel.textAlignment = NSTextAlignmentCenter;
    }
    return _alertTimeLabel;
    
}

//停止计时
- (UIButton *)stopButton {
    if (!_stopButton) {
        _stopButton = [UIButton buttonWithType:(UIButtonTypeSystem)];
        _stopButton.frame = CGRectMake(kWidth / 5, self.backgroundView.frame.origin.y + self.backgroundView.frame.size.height + kWidth / 20, kWidth / 3, kWidth / 3);
        [_stopButton setTitle:@"停止计时" forState:(UIControlStateNormal)];
        [_stopButton setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)];
        [_stopButton setBackgroundImage:[UIImage imageNamed:@"Circle_Red_128px_566287_easyicon.net"] forState:(UIControlStateNormal)];
    }
    return _stopButton;
}

//寻找车位
- (UIView *)showView {
    if (!_showView) {
        _showView = [[UIView alloc] initWithFrame:CGRectMake(kWidth / 5 * 3, self.stopButton.center.y, kWidth * 0.4- kWidth / 40, kWidth / 6)];
        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, _showView.frame.size.width - kWidth / 6, kWidth / 6)];
        label.userInteractionEnabled = YES;
        label.text = @"寻找车位";
        label.font = [UIFont systemFontOfSize:kWidth / 22];
        [_showView addSubview:label];
    }
    return _showView;
}


- (UIButton *)showMapButton {
    if (!_showMapButton) {
        _showMapButton = [UIButton buttonWithType:(UIButtonTypeSystem)];
        _showMapButton.frame = CGRectMake(self.showView.frame.size.width - kWidth / 6, 0, kWidth / 6, kWidth / 6);
        [_showMapButton setImage:[[UIImage imageNamed:@"parking"]imageWithRenderingMode:(UIImageRenderingModeAlwaysOriginal)] forState:(UIControlStateNormal)];
    }
    return _showMapButton;
    
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
